﻿using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace BASIC_ALGORITHM_API.Controllers
{
    /// <summary>
    /// 简单模式
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class SimpleModeController : ControllerBase
    {
        /// <summary>
        /// 两数之和
        /// </summary>
        /// <param name="nums"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        [HttpPost("/simplemode.towsum")]
        public async Task<IActionResult> TowSum(int[] nums, int target)
        {
            Dictionary<int, int> dictionary = new Dictionary<int, int>();
            for (int i = 0; i < nums.Length; i++)
            {
                var index = target - nums[i];
                if (dictionary.ContainsKey(index))
                {
                    return Ok(new int[] { dictionary[index], i });
                }
                dictionary[nums[i]] = i;
            }

            return Ok(await Task.FromResult("无"));
        }
    }
}
